﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AMS.DD35.WebMVP.Views;
using AMS.DD35.WebMVP.Models;
using AMS.DD35.Common.Data;
using AMS.DD35.WebMVP.State;

namespace AMS.DD35.WebMVP.Presenters
{
    public class CharacterPresenter
    {
        ICharacterView _view;
        ICharacterModel _model;
        IStateManager _state;

        public CharacterPresenter(ICharacterView view, ICharacterModel model, IStateManager stateManager)
        {
            this._view = view;
            this._model = model;
            this._state = stateManager;
        }

        public void LoadCharacter()
        {
            long cid = _state.CharacterID;
            _view.CharacterID = cid;
            _view.UserName = _state.UserName;

            if (cid > 0)
            {
                CharacterData characterData = _model.GetCharacter(cid);
                _view.CharacterName = characterData.CharacterName;
                _view.BaseStrength = characterData.BaseStrength;
                _view.BaseDexterity = characterData.BaseDexterity;
                _view.BaseConstitution = characterData.BaseConstitution;
                _view.BaseIntelligence = characterData.BaseIntelligence;
                _view.BaseWisdom = characterData.BaseWisdom;
                _view.BaseCharisma = characterData.BaseCharisma;
                _view.RaceID = characterData.RaceID;
                _view.Experience = characterData.Experience;
                _view.Sex = characterData.Sex;
                _view.Height = characterData.Height;
                _view.HeightUnits = characterData.HeightUnits;
                _view.Weight = characterData.Weight;
                _view.WeightUnits = characterData.WeightUnits;
                _view.HairColor = characterData.HairColor;
                _view.EyeColor = characterData.EyeColor;
                _view.MoralAlignment = characterData.MoralAlignment;
                _view.EthicalAlignment = characterData.EthicalAlignment;
                _view.DeityID = characterData.DeityID;

                // coinage

                // feats

                // skills

                // classes
            }
        }

        public void Save()
        {
            _model.SaveCharacter(_view.GetCharacterData());
        }

        public void SaveSucceeded()
        {
            _view.StatusMessage = "Save Succeeded!";
        }

        public void SaveFailed()
        {
            _view.StatusMessage = "Save Failed!";
        }
    }
}